<?php

$current_page = get_smarty();

$Tournament->delete( 1 );

switch( @$URL[1] )
{
	case '':
	default:
		$_page_content = $current_page->fetch( 'tournament.tpl' );	
		break;
		
	case 'add':		
		$current_page->assign( 'games_list', $Games->get_list() );
		$_page_content = $current_page->fetch( 'tournament_add.tpl' );
		break;
		
	case 'add-action':		
		$tournament_data = array(
				'name'				=> $_POST['nume'],
				'registration_fee'	=> $_POST['registration_fee'],
				'bet'				=> $_POST['bet'],
				'start_time'		=> $_POST['start_time'],
				'registration_time'	=> $_POST['registration_time'],
				'checkin'			=> $_POST['checkin'],
				'game'				=> $_POST['game'],
				'matchup'			=> $_POST['matchup'],
				'players_max'		=> $_POST['players_max'],
				'points_min'		=> $_POST['points_min'],
				'points_max'		=> $_POST['points_max'],
				'details'			=> $_POST['details']
			);
			
		$error = false;
		if ( $tournament_new_id = $Tournament->add( $tournament_data ) )
		{
			
		}
		else
		{
			$error = true;
		}
		
		if ( !$error )
		{
			header( 'Location: /tournament' );
		}
			
		
		break;
		
	case 'list':
		$current_page->assign( 'tournament_list', $Tournament->get_list( 1 ) );
		
		$_page_content .= $current_page->fetch( 'tournament_list.tpl' );
		break;
		
	case 'modify':
		$tournament_id = (int)@$URL[2];
		$tournament = $Tournament->get_id( $tournament_id );
		$current_page->assign( 'tournament', $tournament );
		$current_page->assign( 'tournament_id', $tournament_id );
		$current_page->assign( 'games_list', $Games->get_list() );
		
		$_page_content .= $current_page->fetch( 'tournament_modify.tpl' );	
		break;
	
	case 'modify-action':
		$tournament_data = array(
				'name'				=> $_POST['nume'],
				'registration_fee'	=> $_POST['registration_fee'],
				'bet'				=> $_POST['bet'],
				'start_time'		=> $_POST['start_time'],
				'registration_time'	=> $_POST['registration_time'],
				'checkin'			=> $_POST['checkin'],
				'game'				=> $_POST['game'],
				'matchup'			=> $_POST['matchup'],
				'players_max'		=> $_POST['players_max'],
				'points_min'		=> $_POST['points_min'],
				'points_max'		=> $_POST['points_max'],
				'details'			=> $_POST['details']
			);
		$tournament_id = (int)$_POST['tournament_id'];
		$tournament_modify_result = $Tournament->modifiy( $tournament_id, $tournament_data );
		if ( $tournament_modify_result )
		{
			
		}
		else
		{
			
		}
		
	
		break;
	
}

?>